<template>
	<view class="page-body" :class="[app.setCStyle()]">
		 
		
		
		<view class="flexbox">
		        <view class="headcontent">
		        <h4>进货数量</h4>
		        <ul>
		            <li>
		                <h5>当月进货</h5>
		                <p>{{yueproductnum}}</p>
		            </li>
		            <li>
		                <h5>累计进货</h5>
		                <p>{{allproductnum}}</p>
		            </li>
		            <li>
		                <h5>当月金额</h5>
		                <p>{{yueproductmoney}}</p>
		            </li>
		            <li>
		                <h5>累计金额</h5>
		                <p>{{allproductmoney}}</p>
		            </li>
		        </ul>
		        </view>
		     
		 </view>       
		
		

		<swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
			<swiper-item class="tab-content" v-for="(tabItem,tabIndex) in navList" :key="tabIndex">
				<scroll-view class="hb100" scroll-y @scrolltolower="loadData">
					<!-- 空白页 -->
					<empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
					<!-- 订单列表 -->
					<view v-for="(item,index) in tabItem.orderList" :key="index" class="order-item p20 mb10" style="width: 93%;border: 1px solid #abcdef;border-radius: 10px;margin: 0 auto;">
						<view class="i-top">
							<view class="sn_time">
								<text>订单编号：{{item.order_sn}}</text>
								<text class="time">订单时间：{{item._add_time}}</text>
							</view>
							<text class="state">{{item.ostatus}}</text>
							<!--<u-icon class="del-btn" name="trash-fill" v-if="item.isDelete===1" @click="deleteOrder(item.order_id,index)"></u-icon>-->
						</view>
						<view @click="app.goPage('/pages/jxcshop/order/info?order_id='+item.order_id)">
							<!--<view class="flex mt20" v-for="(goodsItem, goodsIndex) in item.goodsList" :key="goodsIndex"  >
								 
								<view class="flex_bd ">
									<view class="flex">
										<view class="goods_name flex_bd" >{{goodsItem.goods_name}}</view>
										 
									</view>
								 
								</view>
							</view>-->
							<view class="price-box" style="margin-top: 5px;">
								
								订单数量：<text class="num">{{item.goodsNum}}</text>
								订单金额：<text class="price ff base-color">{{item.order_amount}}</text>
							</view>
						</view>
						
						<view class="mt20"> 
							<button v-if="item.isPay == 1" class="fr action-btn recom" @click="app.goPage('pay?order_id='+item.order_id)">立即支付</button>
							<!--<button v-if="item.isCancel == 1" class="fr action-btn" @click="cancelOrder(item.order_id,index)">取消订单</button>-->
							<button v-if="item.invoice_no" class="fr action-btn" @click="app.goPage('shippingLog?order_id='+item.order_id)">查看物流</button>
							<button v-if="item.isSign == 1" class="fr action-btn recom" @click="signAction(item.order_id,index)">确认签收</button>
							<button class="fr action-btn" @click="app.goPage('/pages/jxcshop/order/info?order_id='+item.order_id)">订单详情</button>
							
						</view>
						
					</view>

					<uni-load-more :status="tabItem.loadingType"></uni-load-more>

				</scroll-view>
			</swiper-item>
		</swiper>
		
		<view class="buttoms">
			<button @click="app.goPage('/pages/shop/index/index')">首页</button>
		    <button @click="app.goPage('/pages/jxcshop/goods/index')">门店进货</button>
		    <button class="selectbutton" @click="app.goPage('/pages/jxcshop/order/list')">进货数据</button>
		</view>
		
		
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from "@/components/empty";
	export default {
		components: {
			uniLoadMore,
			empty
		},
		data() {
			return {
				baseUrl: this.config.baseUrl,
				tabCurrentIndex: 0,
				allproductnum:0,
				yueproductnum:0,
				allproductmoney:0,
				yueproductmoney:0,
				param: {
					type: '',
					p: 0
				},
				navList: [{
						type: 'all',
						text: '全部',
						loadingType: 'more',
						orderList: [],
						p: 0
					},
					{
						type: 'waitPay',
						text: '待支付',
						loadingType: 'more',
						orderList: [],
						num:0,
						p: 0
					},
					{
						type: 'waitShipping',
						text: '待发货',
						loadingType: 'more',
						orderList: [],
						num:0,
						p: 0
					},
					{
						type: 'waitSign',
						text: '待收货',
						loadingType: 'more',
						orderList: [],
						num:0,
						p: 0
					},
					{
						type: 'sign',
						text: '已完成',
						loadingType: 'more',
						orderList: [],
						p: 0
					},
				],
			};
		},
		onLoad(options) {
			this.app.isLogin(this);//强制登陆
			if (typeof(options.state) != 'undefined'){
				this.tabCurrentIndex = parseInt(options.state);
			}
			this.getOrderStats();
			this.loadData();
		},
		methods: {
			getOrderStats(){
				this.$u.post('jxcshop/api.order/getOrderStats').then(res => {
					let OrderStats = res.data.orderStats;
					this.navList[1].num = OrderStats.wait_pay_num;
					this.navList[2].num = OrderStats.wait_shipping_num;
					this.navList[3].num = OrderStats.wait_sign_num;
				})
			},
			//获取订单列表
			loadData(source) {
				//这里是将订单挂载到tab列表下
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				if (navItem.loadingType == 'nomore') {
					return;
				}
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				if (navItem.loadingType === 'loading') {
					//防止重复加载
					return;
				}
				navItem.p++;
				this.param.type = navItem.type;
				this.param.p = navItem.p;
				navItem.loadingType = 'loading';
				this.$u.post('jxcshop/api.order/getList', this.param).then(res => {
					navItem.orderList = navItem.orderList.concat(res.data.list);
					//loaded新字段用于表示数据加载完毕，如果为空可以显示空白页
					this.$set(navItem, 'loaded', true);
					//判断是否还有下一页，有是more  没有是nomore
					navItem.loadingType = navItem.p == res.data.page_count ? 'nomore' : 'more';
				})
				
				this.$u.post('jxcshop/api.order/getOrdertongji', this.param).then(res => {
					this.allproductnum = res.data.allproductnum;
					this.yueproductnum = res.data.yueproductnum;
					this.allproductmoney = res.data.allproductmoney;
					this.yueproductmoney = res.data.yueproductmoney;
		  
				})
			},

			//swiper 切换
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				this.loadData('tabChange');
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
			},
			signAction(order_id,_index) {
				let that = this;
				let tip = '确认已收到商品？操作后无法撤回.';
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				uni.showModal({
					title: '提示',
					content: tip,
					showCancel: true,
					success: function(res) {
						if (res.confirm) {
							that.$u.post('jxcshop/api.order/action', {
								order_id: order_id,
								type: 'sign'
							}).then(res => {
								navItem.orderList.splice(_index, 1);
							})
						}
					}
				})
			},
			//删除订单
			deleteOrder(order_id, _index) {
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				this.$u.post('jxcshop/api.order/action', {
					order_id: order_id,
					type:'del'
				}).then(res => {
					navItem.orderList.splice(_index, 1);
				})
			},
			//取消订单
			cancelOrder(order_id, _index) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定取消订单？',
					showCancel: true,
					confirmText: '确定取消',
					cancelText: '放弃取消',
					success: function(res) {
						if (res.confirm) {
							let index = that.tabCurrentIndex;
							let navItem = that.navList[index];
							that.$u.post('jxcshop/api.order/action', {
								order_id: order_id,
								type:'cancel'
							}).then(res => {
								navItem.orderList[_index].ostatus = '已取消';
								navItem.orderList[_index].isDelete = 1;
								navItem.orderList[_index].isPay = 0;
							})
						}
					}
				})	
			}
		},
	}
</script>

<style lang="scss">
	
	
	*{
	            margin:0;padding:0;
	        }
	       .headcontent{
	        width:92%;margin:4% auto;border-radius:6px;border:solid 1px #abcdef;
	       }
	       .headcontent h4{font-weight: normal;font-size:15px;text-align:center;display: block;margin:3% auto;}
	       .headcontent ul li{width:50%;float:left;display: inline-block;text-align: center;}
	       .headcontent ul li h5{color:#666;font-size:14px;font-weight: normal;display: block;margin:2% auto 1% auto;}
	       .headcontent ul li p{font-size:18px;font-weight: 600;margin-bottom: 3%;color:#0D9CD5;}
	       .headcontent ul li:nth-child(3) p,.headcontent ul li:nth-child(4) p{color:#f00;}
	       .headcontent ul{clear:both;overflow: hidden;padding-bottom: 6%;}
	       ul,li{list-style:none;}
	       .flexbox{clear:both;overflow: hidden;}
	       .orderlist ul li{width:92%;margin:4% auto 0 auto;}
	       .orderlist ul li h6{font-size:12px;color:#888;font-weight: normal;display: block;margin-bottom:1%;}
	       .orderlist ul li .contentlist{border-radius:5px;padding:2%;clear:both;overflow: hidden;border:solid 1px #abcdef;}
	       .orderlist ul li .contentlist .leftSide{float:left;}
	       .orderlist ul li .contentlist .leftSide p{width:100%;margin-top:2%;display: block;font-size:13px;color:#333;}
	       .mt20 button{font-size:12px;display:block;color:#fff;background:#F08304;border:none;display: block;border-radius:15px;width:80px;line-height:26px;height: 26px;}
	       .mt20 button:nth-child(2){background:#0D9CD5;}
	       .orderlist ul li .contentlist .rightside{float:right;width:auto;}
	       .buttoms{width:100%;display: flex;position: fixed;bottom:0;left:0;z-index: 999;background:#fff;}
	       .buttoms button{border-radius:6px;width:50%;display: inline-block;line-height: 45px;text-align:center;font-size:18px;border:none;background:#fff;color:#666;}
	       .buttoms .selectbutton{background:#F08304;border:none;color:#fff;}
		   
		   
	page,
	.page-body {
		background: $page-color-base;
		height: 100%;
	}
	.navbar{
		.nav-item{
			position: relative;
			color: #999999;
			&.current{
				&:after{
					border-bottom: 4rpx solid ;
				}
			}	
			.tip-num{
				position: absolute;
				top:5rpx;
				right: 0rpx;
				font-size: 26rpx;
				width: 35rpx;
				text-align: center;
				border-radius: 50%;
				background-color: $font-color-red;
				color: #FFFFFF;
				
			}
		}
	}
	.swiper-box {
		height: calc(100% - 50px);
	}

	.order-item {
		display: flex;
		flex-direction: column;
		background: #fff;
		.i-top {
			display: flex;
			align-items: center;
			height: 50rpx;
			font-size: $font-base;
			color: $font-color-dark;
			position: relative;

			.sn_time {
				flex: 1;

				text {
					display: block;
					font-size: 28rpx;
					color: #666666;
				}

				.time {
					color: $font-color-light;
				}
			}

			.state {
				font-size: 24rpx;
			}

			.del-btn {
				padding: 10rpx 0 10rpx 36rpx;
				font-size: $font-lg;
				color: $font-color-light;
				position: relative;

				&:after {
					content: '';
					width: 0;
					height: 30rpx;
					border-left: 1px solid $border-color-dark;
					position: absolute;
					left: 20rpx;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
		.goods_name {
			//display: block;
			font-size: 28rpx;
			//color: $font-color-dark;
			line-height: 30rpx;
			height: 30rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
		}
		
		.price-box {
			//display: flex;
			justify-content: flex-end;
			align-items: baseline;
			font-size: $font-sm + 2rpx;
			color: $font-color-light;

			.num {
				margin: 0 8rpx;
				color: $font-color-dark;
			}

			.price {
				font-size: $font-lg;
				color: $font-color-gray;

				&:before {
					content: '￥';
					font-size: $font-sm;
					margin: 0 2rpx 0 8rpx;
				}
			}
		}

	}
</style>
